package com.xmy.solution.controller;

import java.time.LocalDateTime;
import java.util.Date;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import org.apache.ibatis.annotations.Param;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.xmy.common.annotation.Log;
import com.xmy.common.core.controller.BaseController;
import com.xmy.common.core.domain.AjaxResult;
import com.xmy.common.enums.BusinessType;
import com.xmy.solution.domain.Chat;
import com.xmy.solution.service.IchatService;
import com.xmy.common.utils.poi.ExcelUtil;
import com.xmy.common.core.page.TableDataInfo;

/**
 * 聊天管理Controller
 * 
 * @author 夏明毅
 * @date 2025-02-20
 */
@RestController
@RequestMapping("/solution/chat")
public class ChatController extends BaseController
{
    @Autowired
    private IchatService chatService;

    /**
     * 查询聊天管理列表
     */
    @PreAuthorize("@ss.hasPermi('solution:chat:list')")
    @GetMapping("/list")
    public TableDataInfo list(Chat chat)
    {
        startPage();
        List<Chat> list = chatService.selectchatList(chat);
        return getDataTable(list);
    }
    @GetMapping("/AppList")
    public TableDataInfo AppList(@Param("dialogueId") Long dialogueId)
    {
        startPage();
        Chat chat=new Chat();
        chat.setDialogueId(dialogueId);
        List<Chat> list = chatService.selectchatList(chat);
        return getDataTable(list);
    }

    /**
     * 实现实时通信
     * @param
     * @return
     */
    @GetMapping("/communication")
    public AjaxResult Communication(@Param("now")@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") Date now, @Param("dialogueId") Long dialogueId)
    {
        Chat chat=new Chat();
        chat.setDialogueId(dialogueId);
        chat.setCreateTime(now);
        List<Chat> list = chatService.selectchatList(chat);
        return success(list);
    }

    /**
     * 导出聊天管理列表
     */
    @PreAuthorize("@ss.hasPermi('solution:chat:export')")
    @Log(title = "聊天管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Chat chat)
    {
        List<Chat> list = chatService.selectchatList(chat);
        ExcelUtil<Chat> util = new ExcelUtil<Chat>(Chat.class);
        util.exportExcel(response, list, "聊天管理数据");
    }

    /**
     * 获取聊天管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('solution:chat:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(chatService.selectchatById(id));
    }

    /**
     * 新增聊天管理
     */
    @PreAuthorize("@ss.hasPermi('solution:chat:add')")
    @Log(title = "聊天管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Chat chat)
    {
        return toAjax(chatService.insertchat(chat));
    }
    @PostMapping("/app")
    public AjaxResult AppAdd(@RequestBody Chat chat)
    {
        return toAjax(chatService.Appinsertchat(chat));
    }
    /**
     * 修改聊天管理
     */
    @PreAuthorize("@ss.hasPermi('solution:chat:edit')")
    @Log(title = "聊天管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Chat chat)
    {
        return toAjax(chatService.updatechat(chat));
    }

    /**
     * 删除聊天管理
     */
    @PreAuthorize("@ss.hasPermi('solution:chat:remove')")
    @Log(title = "聊天管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(chatService.deletechatByIds(ids));
    }
}
